package com.hex.ds.hdrs.period.job.service;

import com.hex.ds.hdrs.common.utils.BaseUtil;
import com.hex.ds.hdrs.period.job.dao.QueueJobInfDao;
import com.hex.ds.hdrs.period.job.po.QueueJobInf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class QueueJobInfService {

    @Autowired
    private QueueJobInfDao queueJobInfDao;


    public List<QueueJobInf> getTaskBlockNum(String appCode) {
        log.info("查询appCode 【QueueJobInfService.getTaskBlockNum】开始=========》");
        Map map = new HashMap();
        map.put("appCode", appCode);
        return queueJobInfDao.getTaskBlockNum(map);
    }

    public List<Map> getBlockAndDependmentNum(String appCode, String startTime) {
        log.info("查询appCode 【QueueJobInfService.getBlockAndDependmentNum】开始=========》");
        Map map=new HashMap();
        map.put("appCode",appCode);
        map.put("startTime",startTime);
        return this.queueJobInfDao.getDependmentNum(map);
    }

    public List<Map> getBlockAndDependmentNum2(String appCode, String startTime) {
        log.info("查询appCode 【QueueJobInfService.getBlockAndDependmentNum】开始=========》");
        Map map=new HashMap();
        map.put("appCode",appCode);
        map.put("startTime",startTime);
        return this.queueJobInfDao.getDependmentNum2(map);
    }

    public List<Map> getBlockAndDependmentNum3(String appCode, String startTime) {
        log.info("查询appCode 【QueueJobInfService.getBlockAndDependmentNum】开始=========》");
        Map map=new HashMap();
        map.put("appCode",appCode);
        map.put("startTime",startTime);
        return this.queueJobInfDao.getDependmentNum3(map);
    }
    public List<Map> getBlockAndDependmentNum4(String appCode, String startTime) {
        log.info("查询appCode 【QueueJobInfService.getBlockAndDependmentNum】开始=========》");
        Map map=new HashMap();
        map.put("appCode",appCode);
        map.put("startTime",startTime);
        return this.queueJobInfDao.getDependmentNum4(map);
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void add(QueueJobInf queueJobInf){
        this.queueJobInfDao.add(queueJobInf);
    }

    public void add(String appCode,String type,Integer num,String crTs){
        QueueJobInf queueJobInf = new QueueJobInf();
        queueJobInf.setPkId(BaseUtil.getPkId());
        queueJobInf.setAppCode(appCode);
        queueJobInf.setType(type);
        queueJobInf.setNum(num);
        queueJobInf.setCrtTs(crTs);
        this.add(queueJobInf);
    }
}
